<!--头部公共部分-->
{include file="common/header" /}

<div style="padding:15px;font-size: 14px;">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">

            <div class="layui-input-inline" style="width: 150px;font-size: 10px;">
                  <script>
                    document.write('<select name="campus_id_all">');
                    document.write('<option value=""></option>');
                    document.write('{foreach name="campus" id="vo"}');
                    var id = parseInt("{$vo.id}");
                    var campus_id = parseInt("{$res.campus_id_all}");
                    if(id === campus_id){
                        document.write('<option value="{$vo.id}" selected>{$vo.campus_name}</option>');
                    }else{
                        document.write('<option value="{$vo.id}">{$vo.campus_name}</option>');
                    }
                    document.write('{/foreach}');
                    document.write('</select>');
                  </script>

                  </div>
              <div class="layui-input-inline" style="width: 150px;font-size: 10px;">

                  <script>
                      document.write('<select name="assignment_all" lay-verify="required">');
                      document.write('<option value=""></option>');
                      document.write('{foreach name="data[24]" id="vo"}');
                      var id = parseInt("{$vo.id}");
                      var assignment = parseInt("{$res.assignment_all}");
                      if(id === assignment){
                          document.write('<option value="{$vo.id}" selected>{$vo.name}</option>');
                      }else{
                          document.write('<option value="{$vo.id}">{$vo.name}</option>');
                      }
                      document.write('{/foreach}');
                      document.write('</select>');
                  </script>

                 </div>
                <div class="layui-input-inline" style="width: 50px;font-size: 10px;">
                <input type="number" id="rate_all"  oninput="Amountallocated()"  min="0" max="100" value="{$res.rate_all}"  name="allocation_rate_all"  autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-mid layui-word-aux" >%</label>

              <label class="layui-form-label" style="font-size: 10px; margin-left: 10px;">分配金额</label>
              <div class="layui-input-inline" style="width:50px;font-size: 10px; ">
                  <script>
                      var rate_all_money = parseInt('{$res.rate_all_money}');
                      rate_all_money = (rate_all_money /100);
                      document.write('<input type="text" id="rate_all_money"   value= "'+ rate_all_money +'"  name="allocation_rate_all_money"  autocomplete="off" readonly placeholder="所分金额" class="layui-input">');
                  </script>

              </div>

               </div>


        <div class="layui-inline">
            <input class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="form_all" style="width:80px;" value="保存" readonly>
            <input class="layui-btn layui-btn-sm layui-btn-primary" lay-submit style="width:80px;" lay-filter="cancle_all" value="取消" readonly>

        </div>

    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}
<script>

    function Amountallocated() {
        let rate = parseInt(document.getElementById("rate_all").value)/100;
        let amount_already_all = parseInt("{$res.amount_already_all}") / 100;
        let money = (rate * amount_already_all).toFixed(2);
        $('#rate_all_money').val(money);
    }
    
    layui.use(['element', 'jquery', 'form', 'laydate', 'layer'], function () {
        let $ = layui.$,
            layer = layui.layer,
            form = layui.form,
            element = layui.element,
            laydate = layui.laydate,
            jquery = layui.jquery;

        //日期
        laydate.render({
            elem: '#date'
            ,trigger: 'click'
        });

        //监听提交
        form.on('submit(form_all)', function (data) {
            let rate = parseInt(document.getElementById("rate_all").value)/100;
            let amount_already_all = parseInt("{$res.amount_already_all}") / 100;
            let money = (rate * amount_already_all).toFixed(2);
            var field = {};
            field.id = '{$id}';
            field.campus_id_all = $('select[name=campus_id_all] option:selected').val();
            field.rate_all = document.getElementById("rate_all").value;
            field.rate_all_money = money;
            $.ajax({
                url: '/admin/finance/save_all',
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 1) {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }

                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });


        //监听取消
        form.on('submit(cancle_all)', function (data) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
            return false;
        });

    });
</script>
